package com.tledu.production.controller.common;

import com.tledu.production.mapper.people.DepartmentMapper;
import com.tledu.production.mapper.people.EmployeeMapper;
import com.tledu.production.model.people.Department;
import com.tledu.production.model.people.Employee;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Antg
 * @date 2021/8/17  19:32
 */
@Controller
@AllArgsConstructor
public class CommonPeopleController {
    private DepartmentMapper departmentMapper;
    private EmployeeMapper employeeMapper;

    //部门
    @GetMapping("/people/dep-list")
    public String goDepList() {
        return "people/dep-list";
    }

    @GetMapping("/people/dep-add")
    public String goDepAdd() {
        return "people/dep-add";
    }

    @GetMapping("/people/dep-edit")
    public String goDepEdit(String id, HttpServletRequest req) {
        Department dep = departmentMapper.findById(id);
        if (dep == null) {
            return "error/error";
        }
        req.setAttribute("dep", dep);
        return "people/dep-edit";
    }

    @GetMapping("/people/dep-detail")
    public String goDepDetail(String id, HttpServletRequest req) {
        Department dep = departmentMapper.findById(id);
        if (dep == null) {
            return "error/error";
        }
        req.setAttribute("dep", dep);
        return "people/dep-detail";
    }

    //员工

    @GetMapping("/people/emp-list")
    public String goEmpList() {
        return "people/emp-list";
    }

    @GetMapping("/people/emp-add")
    public String goEmpAdd() {
        return "people/emp-add";
    }

    @GetMapping("/people/emp-edit")
    public String goEmpEdit(String id, HttpServletRequest req) {
        Employee employee = employeeMapper.findById(id);
        if (employee == null) {
            return "error/error";
        }
        req.setAttribute("emp", employee);
        return "people/emp-edit";
    }
}
